/*
 * Copyright (C) 2014 Lucid Wolf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.lucidhex;

import com.lucidhex.erfworld.ErfWorldDefaultTemplate;
import com.lucidhex.io.LucidWorldParser;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;


/**********************************
  This is the main class of a Java program to play a game based on hexagonal tiles.
  The mechanism of handling hexes is in the file hexmech.java.

  Written by: M.H.
  Date: December 2012

 ***********************************/

public class LucidWorld implements LucidXMLObject{

    //constants and global variables
    public static LucidWorldTemplate NULLTEMPLATE = new NullWorldTemplate();
    public static int VER = 1;
    // currently one board (Multi for players
    private LucidBoard board = new LucidBoard();
    private LucidTimeManager timeMan = new LucidTimeManager();
    private LucidUnitManager unitMan = new LucidUnitManager();
    private LucidWorldTemplate defaults = LucidWorld.NULLTEMPLATE;

    public LucidWorld() {
        board.setWorld(this);
    }
    public LucidBoard getBoard(){
        return board;
    }
    @Override
    public String getTag() {
        return "LucidWorld";
    }

    @Override
    public void getChildren(Collection<Object> children) {
        children.add(board);
        children.add(timeMan);
        children.add(unitMan);
    }

    @Override
     public void addField(String key, String value){
        if(key.equalsIgnoreCase("Defaults")){
            if(value.equalsIgnoreCase(ErfWorldDefaultTemplate.NAME)){
                setWorldTemplate(new ErfWorldDefaultTemplate());
            }
        }
    }
    @Override
    public void getFields(Map<String, String> attrib) {
        if(defaults != NULLTEMPLATE){
            attrib.put("Defaults", defaults.getName());
        }
        attrib.put("Version", ""+VER);
    }
    @Override
    public void addChild(Object aChild) {
        //board = (LucidBoard)aChild;
    }

    public boolean isEmpty() {
        return board.isEmpty();
    }

    public void clear() {
        board.clear();
    }
    public LucidWorldTemplate getDefaults(){
        return defaults;
    }
    @Override
    public boolean writeToXml() {
        return true;
    }

    public void setWorldTemplate(LucidWorldTemplate aTemplate) {
        defaults = aTemplate;
        board.setWorld(this);
    }
   public LucidWorldTemplate getWorldTemplate() {
        return defaults;
    }

    @Override
    public void parseLink(LucidWorldParser parser) {
        parser.setParsingWorld(this);
    }

    protected void setBoard(LucidBoard b) {
        board = b;
    }
}